package com.example.controller;

import com.example.common.util.PageResult;
import com.example.common.util.R;
import com.example.entity.Student;
import com.example.service.IStudentService;
import com.example.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private IStudentService studentService;

	@RequestMapping("/list")
	public R getStudent() {
		return R.ok().data("list",studentService.list());
	}

	@GetMapping("/findByPage/{page}/{pageSize}")
	public R findByPage(@PathVariable("page") Integer page,
	                    @PathVariable("pageSize") Integer pageSize) {
		PageResult<Student> pr = studentService.findByPage(page,pageSize);
		return R.ok().data("pr",pr);
	}
	@PostMapping("/search/{page}/{pageSize}")
	public R search(@PathVariable("page") Integer page,
	                @PathVariable("pageSize") Integer pageSize,
	                @RequestBody(required = false) StudentVO vo){
		PageResult<Student> pr = studentService.search(page,pageSize,vo);
		return R.ok().data("pr",pr);
	}
}
